<template>
  <el-container id="overall">
    <el-header>
      <strong>{{ title }}</strong>
      <div class="header-avatar">
        <el-dropdown>
          <span class="el-dropdown-link">
            {{ userInfo.name }}<i class="el-icon-arrow-down el-icon--right"></i>
          </span>
          <el-dropdown-menu slot="dropdown">
            <router-link to="/userCenter"
              ><el-dropdown-item> 个人中心 </el-dropdown-item></router-link
            >
            <el-dropdown-item @click.native="logout"> 退出 </el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>
      </div>
    </el-header>
    <el-container>
      <el-aside style="width: 1">
        <SideMenu id="menu"></SideMenu>
      </el-aside>
      <el-main>
        <Tabs style="margin: 0 15px"></Tabs>
        <div style="margin: 0 15px">
          <router-view></router-view>
        </div>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
import SideMenu from "./inc/SideMenu.vue";
import Tabs from "./inc/Tabs.vue";
export default {
  name: "Home",
  computed: {
    userInfo: {
      get() {
        return this.$store.state.userInfo.info;
      },
    },
  },
  components: {
    SideMenu,
    Tabs,
  },
  data() {
    return {
      title: "OKR目标管理系统",
    };
  },
  methods: {
    getUserInfo() {
      this.$axios
        .get("/user/info")
        .then((res) => {
          // console.log(res.data.data);
          this.$store.commit("setUserinfo", res.data.data);
        })
        .catch((err) => {
          this.logout();
        });
    },
    logout() {
      this.$axios.post("/logout").then((res) => {
        // console.log(res.data);
        this.$store.commit("resetState");
        this.$router.push("/login");   
      });
    },
    selectMenu(item) {
      this.$store.commit("addTab", item);
    },
  },
  // computed: {
  //   menuList: {
  //     get(){
  //       return this.$store.state.menus.menuList
  //     }
  //   },
  //   title: {
  //     get(){
  //       return this.$store.state.title
  //     }
  //   }
  // },
  created() {
    this.getUserInfo();
  },
};
</script>

<style scoped>
a {
  text-decoration: none;
}
.router-link-active {
  text-decoration: none;
}
.header-avatar {
  float: right;
  width: 150px;
  display: flex;
  justify-content: space-around;
  align-items: center;
}

.el-header {
  text-align: center;
  line-height: 60px;
  padding: 0px;
  background-image: url("../assets/images/head.jpeg");
  background-size: 100% 100%;
}

.el-aside {
  text-align: left;
  width: 210px;
  overflow: hidden;
}

.el-main {
  color: #333;
  padding: 0px;
  overflow: hidden;
}

body > .el-container {
  margin-bottom: 40px;
}

.el-container:nth-child(5) .el-aside,
.el-container:nth-child(6) .el-aside {
  line-height: 260px;
}

.el-container:nth-child(7) .el-aside {
  line-height: 320px;
}

.el-dropdown-link {
  cursor: pointer;
}
.el-icon-arrow-down {
  font-size: 10px;
}
#overall {
  background-image: url("../assets/images/overall.png");
  background-size: 100% 100%;
  min-height: 100vh;
}
#menu {
  margin-left: 10px;
}
</style>